package com.pf.service.impl;

import com.pf.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2022/6/28 23:15
 */
@Slf4j
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    @Qualifier("asyncServiceExecutor")
    private ThreadPoolTaskExecutor taskExecutor;

    @Override
    public void runnableTest() {
        // 模拟业务方法
        log.info(">>>>> runnableTest...");

        // 模拟异步业务
        taskExecutor.execute(() -> {
            try {
                test();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }

    private void test() throws Exception {
        log.info(">>>>> test");
        Thread.sleep(5000);
    }
}
